#ifndef __MESSAGE_H
#define __MESSAGE_H

#include "../serialize/decode.h"

namespace conn {

// type, seq, cmd, datas

// SimpleReq or Req
class Message {

public:
    Message(const uint8_t *buf = nullptr, uint8_t len = 0)
        : m_buf(buf), m_len(len) {}

    uint8_t type() const { return m_buf[0]; }
    uint8_t seq() const { return m_buf[1]; }
    uint8_t cmd() const { return m_buf[2]; }
    
    uint8_t len() const { return m_len; }

    template <typename... Ts> utils::Error parse_req(Ts &...ts) const {
        return serialize::decode_all(m_buf + 3, m_len - 3, ts...);
    }

private:
    const uint8_t *m_buf;
    uint8_t m_len;
};

} // namespace conn

#endif
